﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Acms.DatabaseTest.Helpers
{
    public static class PostHelpers
    {
        /*public static void Post_Add(this TestConnection source, int id, int siteId, Guid postGuid, Guid? parentGuid, string name, string displayName, int sequence, int templateId, int? thumbnailId, string summary, DateTime createdDateTime, DateTime? publishFrom, DateTime? publishTo, string notes, bool requiresPublishing, bool readyToPublish, bool developerLocked, bool deleted, string titleSummary, string metaKeywords)
        {
            string sql = @"
            
            set identity_insert acms.posts on 

            INSERT INTO [AcmsTestDB].[acms].[Posts]
               ([Id]
               ,[SiteId]
               ,[PostGuid]
               ,[ParentGuid]
               ,[Name]
               ,[DisplayName]
               ,[Sequence]
               ,[TemplateId]
               ,[ThumbnailId]
               ,[Summary]
               ,[CreatedDateTime]
               ,[PublishFrom]
               ,[PublishTo]
               ,[Notes]
               ,[RequiresPublishing]
               ,[ReadyToPublish]
               ,[DeveloperLocked]
               ,[Deleted]
               ,[TitleSummary]
               ,[MetaKeywords])
         VALUES
               (@0,@1,@2,@3,@4,@5,@6,@7,@8,@9,@10,@11,@12,@13,@14,@15,@16,@17,@18,@19)
            
            set identity_insert acms.posts off
            ";
            source.Execute(sql, new ParamCollection()
                .AddInputParam(System.Data.SqlDbType.Int, id)
                .AddInputParam(System.Data.SqlDbType.Int, siteId)
                .AddInputParam(System.Data.SqlDbType.UniqueIdentifier, postGuid)
                .AddInputParam(System.Data.SqlDbType.UniqueIdentifier, parentGuid)
                .AddInputParam(System.Data.SqlDbType.VarChar, name)
                .AddInputParam(System.Data.SqlDbType.VarChar, displayName)
                .AddInputParam(System.Data.SqlDbType.Int, sequence)
                .AddInputParam(System.Data.SqlDbType.Int, templateId)
                .AddInputParam(System.Data.SqlDbType.Int, thumbnailId)
                .AddInputParam(System.Data.SqlDbType.VarChar, summary)
                .AddInputParam(System.Data.SqlDbType.DateTime, createdDateTime)
                .AddInputParam(System.Data.SqlDbType.DateTime, publishFrom)
                .AddInputParam(System.Data.SqlDbType.DateTime, publishTo)
                .AddInputParam(System.Data.SqlDbType.VarChar, notes)
                .AddInputParam(System.Data.SqlDbType.Int, requiresPublishing)
                .AddInputParam(System.Data.SqlDbType.Int, readyToPublish)
                .AddInputParam(System.Data.SqlDbType.Bit, developerLocked)
                .AddInputParam(System.Data.SqlDbType.Bit, deleted)
                .AddInputParam(System.Data.SqlDbType.VarChar, titleSummary)
                .AddInputParam(System.Data.SqlDbType.VarChar, metaKeywords)
                );
        }*/

        public static List<Dictionary<string, object>> Post_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.Posts");
            return source.ExecuteWithResults(sql);
        }

        public static Dictionary<string, object> Post_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.posts where id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection().AddInputParam(System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }



//        public static void Post_Add(this TestConnection source, Guid postGuid, Guid parentGuid, int id, int siteId, int sequence, int? templateId, int? thumbnailId, DateTime createdDateTime, DateTime? publishFrom, DateTime? publishTo, bool requiresPublishing, bool readyToPublish, bool developerLocked, bool deleted, string name, string displayName, string summary, string notes, string titleSummary, string metaKeywords, byte[] versionId)
//        {
//            string sql = @"
//            
//            set identity_insert acms.Posts on 
//
//            INSERT INTO [acms].Posts ([PostGuid], [ParentGuid], [Id], [SiteId], [Sequence], [TemplateId], [ThumbnailId], [CreatedDateTime], [PublishFrom], [PublishTo], [RequiresPublishing], [ReadyToPublish], [DeveloperLocked], [Deleted], [Name], [DisplayName], [Summary], [Notes], [TitleSummary], [MetaKeywords], [VersionId])
//			VALUES (@2, @3, @0, @1, @6, @7, @8, @10, @11, @12, @14, @15, @16, @17, @4, @5, @9, @13, @19, @20, @18)
//            
//            set identity_insert acms.Posts off
//            ";
//            source.Execute(sql, new ParamCollection()
//                .AddInputParam(System.Data.SqlDbType.UniqueIdentifier, postGuid)
//                .AddInputParam(System.Data.SqlDbType.UniqueIdentifier, parentGuid)
//                .AddInputParam(System.Data.SqlDbType.Int, id)
//                .AddInputParam(System.Data.SqlDbType.Int, siteId)
//                .AddInputParam(System.Data.SqlDbType.Int, sequence)
//                .AddInputParam(System.Data.SqlDbType.Int, templateId)
//                .AddInputParam(System.Data.SqlDbType.Int, thumbnailId)
//                .AddInputParam(System.Data.SqlDbType.DateTime, createdDateTime)
//                .AddInputParam(System.Data.SqlDbType.DateTime, publishFrom)
//                .AddInputParam(System.Data.SqlDbType.DateTime, publishTo)
//                .AddInputParam(System.Data.SqlDbType.Bit, requiresPublishing)
//                .AddInputParam(System.Data.SqlDbType.Bit, readyToPublish)
//                .AddInputParam(System.Data.SqlDbType.Bit, developerLocked)
//                .AddInputParam(System.Data.SqlDbType.Bit, deleted)
//                .AddInputParam(System.Data.SqlDbType.VarChar, name)
//                .AddInputParam(System.Data.SqlDbType.VarChar, displayName)
//                .AddInputParam(System.Data.SqlDbType.VarChar, summary)
//                .AddInputParam(System.Data.SqlDbType.VarChar, notes)
//                .AddInputParam(System.Data.SqlDbType.VarChar, titleSummary)
//                .AddInputParam(System.Data.SqlDbType.VarChar, metaKeywords)
//                .AddInputParam(System.Data.SqlDbType.Timestamp, versionId)
//            );
//        }

    }


}
